package com.ctshk.rpc.custom.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.custom.base.CustomBaseMapper;
import com.ctshk.rpc.custom.dto.quotation.CollectionTouristFeeDTO;
import com.ctshk.rpc.custom.dto.trip.CollectionTouristPriceDTO;
import com.ctshk.rpc.custom.dto.trip.TouristCollectionItemDTO;
import com.ctshk.rpc.custom.entity.CustomizedTripScheduleCollectionTouristFee;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 团期代收费用旅客类型价格 Mapper 接口
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-21
 */
public interface CustomizedTripScheduleCollectionTouristFeeMapper extends CustomBaseMapper<CustomizedTripScheduleCollectionTouristFee> {

    /**
     * 代收费用明细列表
     * @param collectionId
     * @return
     */
    @Select("SELECT a.tourist_type_name,a.total_amount AS price,b.people_num AS number,(a.total_amount * b.people_num) AS totalAmount \n" +
            "FROM t_customized_trip_schedule_collection_tourist_fee a LEFT JOIN t_customized_quotation_tourist_type b ON a.tourist_type_id = b.id\n" +
            "WHERE a.collection_id = #{collection_id} and a.is_deleted = 0 ORDER BY b.sort")
    List<CollectionTouristFeeDTO> queryCollectionTouristFeeDetailList(@Param("collection_id") Long collectionId);

    /**
     * 代收费用旅客单价
     * @param scheduleId
     * @return
     */
    @Select("SELECT tourist_type_id,tourist_type_name \n" +
            "FROM t_customized_trip_schedule_collection_tourist_fee\n" +
            "WHERE schedule_id = #{schedule_id}\n" +
            "GROUP BY tourist_type_id")
    List<CollectionTouristPriceDTO> getCollectionPriceByTourist(@Param("schedule_id") Long scheduleId);

    /**
     * 旅客类型代收费用列表
     * @param touristTypeId
     * @param scheduleId
     * @return
     */
    @Select("SELECT b.main_data_id,b.project_name,a.currency_id,a.total_amount,a.exchange_rate \n" +
            "FROM t_customized_trip_schedule_collection_tourist_fee a\n" +
            "LEFT JOIN t_customized_trip_schedule_collection_fee b ON a.collection_id = b.id\n" +
            "WHERE a.tourist_type_id = #{tourist_type_id} AND b.schedule_id = #{schedule_id} AND b.is_deleted = 0")
    List<TouristCollectionItemDTO> sumCollectionItemList(@Param("tourist_type_id")Long touristTypeId,@Param("schedule_id") Long scheduleId);
}
